package com.ruoyi.syf.handler.escalation;

import com.ruoyi.syf.common.constant.EscalationConfigEnum;
import com.ruoyi.syf.domain.EscalationConfig;
import com.ruoyi.syf.service.IEscalationConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * 初始化上报配置
 */
@Component
public class EscalationConfigHandler {

    @Autowired
    private IEscalationConfigService escalationConfigService;

    @PostConstruct
    private void init(){
        List<EscalationConfig> list = escalationConfigService.list();
        for (EscalationConfigEnum item : EscalationConfigEnum.values()) {
            boolean flag = false;
            for (EscalationConfig config : list){
                if (item.getValue().equals(config.getConfigKey())) {
                    flag = true;
                    break;
                }
            }
            if (!flag){
                escalationConfigService.saveConfig(item);
            }
        }

    }

}
